
import { orderList , orderPayment } from '../../../../api/order'
import { find , facePay} from '../../../../api/payment'
// import { list } from '../../../../api/account'
import { accountList } from '../../../../api/payment'

const util = require('../../../../utils/util.js')
Page({
  data: {
    id:'',
    tranSn:'',
    depositId:'',
    name:'',
    credit:'',
    debit:'',
    PaymentAmount:'0.00',
    findForm:{},
    paymentimage:""
  },
  onLoad: function(options) {
    var _this = this;
    // if(options.item){
    //   this.setSaveParameters(JSON.parse(options.item))
    // }
    _this.findClick(options.id)
    // _this.listClick()

  },
  findClick(data){
    var _this = this
    find(data).then(res=>{
      console.log(res)
      _this.data.findForm = res.data
      _this.setData({
        findForm:_this.data.findForm
      })

      this.listClick()

    })
  },
  listClick(){
    var _this = this
    // list().then(res=>{
      let params = {
        sn:this.data.findForm.payment.sn
      }
      console.log(this.data.findForm.payment.sn,"333333333333333333333333333333")
    accountList(params).then(res=>{
      let bankInList=[]
      res.data.forEach(item=>{
          if(item.bankInfoId==1){
            bankInList.push(item)
          }
      })
      this.data.paymentimage=bankInList[0].qrcode
      this.setData({
        paymentimage:this.data.paymentimage
      })
    })
  },
  previewImage: function(e) {
    var current = e.target.dataset.src;
    wx.previewImage({
      current: current,
      urls: [current]
    })
  },
  priceFormat(value) {
    var toFixedNum = Number(value).toFixed(3);
    var realVal = toFixedNum.substring(0, toFixedNum.toString().length - 1);
    return realVal;
  },
  setSaveParameters(item){
    console.log(item,"11111111111111111111111321321231")
    this.data.id = item.id
    this.data.name = item.consignee
    this.data.PaymentAmount = this.priceFormat(item.subPrice)
    console.log(this.data.name ,"1111111111111111111111")
    console.log(item.name ,"1111111111111111111111")
    this.setData({
      name: this.data.name,
      PaymentAmount:this.data.PaymentAmount,
    })
  },
  metaClick(data) {
    this.data.tranSn = data.detail.images[0]
  },
  confirmClick() {
    var _this = this
    if( this.data.tranSn == "" ){
      wx.showToast({
        title: '请先上传付款凭证',
        icon: 'none',
        duration: 2000
      })      
      return false
    }
      console.log(_this.data.findForm,"1111111111111321321")
    var data = {
      sn:_this.data.findForm.payment.sn,
      tranSn:this.data.tranSn
    }
    facePay(data).then(res=>{
      wx.showToast({
        title: "支付成功",
        icon: 'none',
        duration: 3000,
        success:function(){
          setTimeout(() => {
            wx.navigateBack({
                delta: 1
            })
          }, 1000)
        }
      })
    }).catch(error=>{
      wx.showToast({
        title: error.content,
        icon: 'none',
        duration: 3000,
      })
    })


  }
})
